<template>
  <div class="tab-control">
    <div
      class="tab-control-item"
      v-for="(item, index) in titles"
      :key="index"
      @click="itemClick(index)"
    >
      <span :class="{ active: index == currentIndex }">{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabControl",
  props: {
    // title 标题
    titles: {
      type: Array,
      defauft() {
        return [];
      }
    }
  },
  data() {
    return {
      currentIndex: 0
    };
  },
  methods: {
    itemClick(index) {
      this.currentIndex = index;
      this.$emit("tabClick", index);
    }
  }
};
</script>

<style lang="less" scoped>
.tab-control {
  background: #fff;
  display: flex;
  height: 44px;
  line-height: 44px;
  > div {
    flex: 1;
    text-align: center;
    > span {
      padding: 5px;
      &.active {
        color: var(--color-high-text);
        border-bottom: 3px solid var(--color-tint);
      }
    }
  }
}
</style>
